package com.sftz.modules.minapp.myorder.dto;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import lombok.Data;

import com.sftz.assets.enums.OrderStatusEnum;
import com.sftz.assets.enums.OrderTypeEnum;
import com.sftz.assets.enums.PayMethodsStatusEnum;
import com.sftz.assets.enums.RequiredStateEnum;
import com.uxuexi.core.common.util.EnumUtil;

/**
 * @author   王宏伟
 * @Date	 2018年12月11日 	 
 */
@Data
public class MyOrderDto {

	/**系列  课程  专业id*/
	private Integer id;

	/**订单id*/
	private Integer orderId;

	/**商品名称*/
	private String productName;

	/**课程和专业的封面*/
	private String picture;

	/**订单号*/
	private String orderNum;

	/**金额*/
	private Double amountOfMoney;
	private String amountOfMoneyName;

	/**订单创建时间*/
	private Date orderCreateTime;

	/**倒计时*/
	private String countDown;

	/**订单状态*/
	private Integer orderState;

	/**订单类型（1系列、2课程、3作品）*/
	private Integer orderType = OrderTypeEnum.COURSE.intKey();

	/**系列名称*/
	private String seriesName;

	/**学院名称*/
	private String institutionName;

	/**课程分数*/
	private Integer score;

	/**机构课程类型（1学历课程，2非学历课程）*/
	private Integer insCourseType;

	/**支付方式：1线上，2线下*/
	private Integer payMethod;

	/**学习人数*/
	private Integer studyCount;

	/**是否收费：0免费，1收费*/
	private Integer charge;

	/**支付方式名称*/
	private String payMethodName;

	/**支付方式：1已付款-实付款，2待付款-需付款*/
	private String paymentName;

	/*****************************************************/

	/**订单专业名称*/
	private String orderMajorName;

	/**存放订单状态*/
	private String orderStateName;

	/**已支付订单数量*/
	private Integer havePaid;

	/**未支付订单数量*/
	private Integer notPaid;

	/**订单总数量*/
	private Integer orderCount;

	/**学分名称*/
	private String scoreName;

	/**订单按钮名称*/
	private String orderButtonName;

	/** 总条数 */
	private Integer count;

	/**
	 * 获取倒计时(秒数)
	 * @author	王宏伟
	 * @Date	2018年12月19日
	 */
	public String getCountDown() {
		Date date = new Date();
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(this.orderCreateTime);
		calendar.add(calendar.DATE, 1); //把日期往后增加一天,整数  往后推,负数往前移动 
		Date newOrderCreateTime = calendar.getTime();
		int dateTime = (int) ((newOrderCreateTime.getTime() - date.getTime()) / 1000);
		//判断订单是否过期：大于0没过期，小于0过期
		String remainingTimeString = String.valueOf(dateTime);
		this.countDown = remainingTimeString;
		return this.countDown;
	}

	public String getAmountOfMoneyName() {
		if (this.charge == 0) {
			this.amountOfMoneyName = "免费";
		} else if (this.charge == 1) {
			this.amountOfMoneyName = "￥ " + this.amountOfMoney;
		}
		return this.amountOfMoneyName;
	}

	public String getPayMethodName() {
		if (this.payMethod == PayMethodsStatusEnum.ONLINEPAY.intKey()
				&& this.orderState == OrderStatusEnum.COMPLETE.intKey()) {
			this.payMethodName = "在线支付";
		} else if (this.payMethod == PayMethodsStatusEnum.OFFLINEPAY.intKey()
				&& this.orderState == OrderStatusEnum.COMPLETE.intKey()) {
			this.payMethodName = "线下支付";
		} else {
			this.payMethodName = "待付款";
		}
		return this.payMethodName;
	}

	public String getPaymentName() {
		if (this.orderState == OrderStatusEnum.COMPLETE.intKey()) {
			this.paymentName = "实付款";
		} else {
			this.paymentName = "需付款";
		}
		return this.paymentName;
	}

	/**
	 * 给订单按钮赋值
	 */
	public String getOrderButtonName() {
		orderButtonName = "";
		//WAIT_PAY(1, "等待付款"), PAYED(2, "已支付"), CANCEL(3, "已取消"), COMPLETE(4, "已完成");
		OrderStatusEnum os = EnumUtil.get(OrderStatusEnum.class, this.orderState);
		switch (os) {
		case WAIT_PAY:
			orderButtonName = "去支付";
			break;
		case COMPLETE:
			orderButtonName = "已完成";
			break;
		default:
			orderButtonName = "";
			break;
		}
		return orderButtonName;
	}

	/**
	 * 给订单状态赋值
	 */
	public String getOrderStateName() {
		orderStateName = "";
		//WAIT_PAY(1, "等待付款"), PAYED(2, "已支付"), CANCEL(3, "已取消"), COMPLETE(4, "已完成");
		OrderStatusEnum os = EnumUtil.get(OrderStatusEnum.class, this.orderState);
		switch (os) {
		case WAIT_PAY:
			orderStateName = "等待付款";
			break;
		case PAYED:
			orderStateName = "已支付";
			break;
		case CANCEL:
			orderStateName = "";
			break;
		case COMPLETE:
			orderStateName = "已完成";
			break;
		default:
			orderStateName = "";
			break;
		}
		return orderStateName;
	}

	/**
	 * 给学分赋值
	 */
	public String getScoreName() {
		scoreName = "";
		//MAJOR(1, "专业"), COURSE(2, "课程");
		if (this.orderType == OrderTypeEnum.COURSE.intKey()) {
			RequiredStateEnum ot = EnumUtil.get(RequiredStateEnum.class, this.orderType);
			//ELECTIVES(1, "专业统修课"), REQUIRED(2, "专业核心课 "), PASSTOCHOOSE(3, "专业通选课");
			switch (ot) {
			case ELECTIVES:
				scoreName = "(专业统修课) 			学分：" + this.score;
				break;
			case REQUIRED:
				scoreName = "(专业核心课) 			学分：" + this.score;
				break;
			case PASSTOCHOOSE:
				scoreName = "(专业通选课) 			学分：" + this.score;
				break;
			default:
				scoreName = "";
				break;
			}
		}
		return scoreName;
	}

	/**
	 * 给专业名称赋值
	 */
	public String getOrderMajorName() {
		orderMajorName = "";
		//COURSESERIES(1, "课程系列"), COURSE(2, "课程"), WORKS(3, "作品");
		//如果是课程
		if (this.orderType == OrderTypeEnum.COURSE.intKey()) {
			OrderTypeEnum ot = EnumUtil.get(OrderTypeEnum.class, this.orderType);
			//给追加
			switch (ot) {
			case COURSESERIES:
				orderMajorName = "所属专业：《" + this.seriesName + "》";
				break;
			case COURSE:
				orderMajorName = "";
				break;
			default:
				orderMajorName = "";
				break;
			}
		}
		return orderMajorName;
	}

}
